<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>DataType.XML Tests</title>
<script type="text/javascript" src="../../../build/yui/yui.js"></script>
<script type="text/javascript" src="../../../build/datatype/datatype-debug.js"></script>
</head>

<body class="yui3-skin-sam">
<h1>DataType.XML Tests</h1>
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>

<script type="text/javascript">

(function() {
    YUI({
        base: "../../../build/",
        //filter: "debug",
        logInclude:{"TestRunner":true},
        useConsole: true
    }).use("console", "test", "dump", "datatype-xml", function(Y) {
        
        // Set up the page
        var ASSERT = Y.Assert,
            ARRAYASSERT = Y.ArrayAssert,
            btnRun = Y.one("#btnRun"),
            myConsole = new Y.Console().render();
            
        btnRun.set("disabled", false);
        Y.on("click", function(){
            Y.Test.Runner.run();
        }, btnRun);


        var testParse = new Y.Test.Case({
            name: "XML Parse Tests",
        
            testUndefined: function() {
                var xmldoc = Y.DataType.XML.parse();
                ASSERT.isNull(xmldoc, "Expected null.");
            },
            
            testNull: function() {
                var xmldoc = Y.DataType.XML.parse(null);
                ASSERT.isNull(xmldoc, "Expected null.");
            },

            testStrings: function() {
                var xmldoc = Y.DataType.XML.parse("<myroot><item type='foo'><name>Abc</name><rank>1</rank></item><item type='bar'><name>Def</name><rank>2</rank></item><item type='bat'><name>Ghhi</name><rank>3</rank></item></myroot>");
                ASSERT.areSame("item", xmldoc.documentElement.firstChild.nodeName, "Incorrect node name.");
                ASSERT.areSame(3, xmldoc.getElementsByTagName("item").length, "Incorrect length.");
            }
        });
            
        var testFormat = new Y.Test.Case({
            name: "XML Format Tests",

            testUndefined: function() {
                var output = Y.DataType.XML.format();
                ASSERT.areSame("", output, "Expected empty string.");
            },

            testNull: function() {
                var output = Y.DataType.XML.format(null);
                ASSERT.areSame("", output, "Expected empty string.");
            },

            testFormat: function() {
                var origString = "<myroot><item type=\"foo\"><name>Abc</name><rank>1</rank></item><item type=\"bar\"><name>Def</name><rank>2</rank></item><item type=\"bat\"><name>Ghhi</name><rank>3</rank></item></myroot>",
                    xmldoc = Y.DataType.XML.parse(origString),
                    newString = Y.DataType.XML.format(xmldoc),
                    ie9String = '<myroot xmlns=""><item type="foo"><name>Abc</name><rank>1</rank></item><item type="bar"><name>Def</name><rank>2</rank></item><item type="bat"><name>Ghhi</name><rank>3</rank></item></myroot>';

                ASSERT.isTrue((newString.indexOf(origString) > -1) || (newString === ie9String), "Expected new string same as old string.");
            }
        });

        var suite = new Y.Test.Suite({name:"DataType.XML Test Suite"});
        suite.add(testParse);
        suite.add(testFormat);

        Y.Test.Runner.setName("DataType.XML Test Runner");
        Y.Test.Runner.add(suite);
        Y.Test.Runner.run();
    });
})();
</script>
</body>
</html>
